# == Schema Information
# Schema version: 38
#
# Table name: books
#
#  id               :integer(11)     not null, primary key
#  user_id          :integer(11)
#  title            :string(255)
#  subtitle         :string(255)
#  author           :string(255)
#  isbn             :string(255)
#  publisher        :string(255)
#  description      :text
#  description_html :text
#  created_at       :datetime
#  udpated_at       :datetime
#

class Book < ActiveRecord::Base
  cattr_reader :per_page
  @@per_page = 10
  
  has_one :book_cover, :dependent => :destroy
  belongs_to :user
  
  # Virtual attribute for book cover
  attr_accessor :cover
  
  format_attribute :description
  
  def self.all(page)
    self.paginate(:all, :page => page || 1, :include => :book_cover, :order => "updated_at desc")
  end
  
end
